#pragma once

#include "HashTable.h"

namespace xsc
{
	template<typename K,typename V,typename hash = HashFunc<K>>
	class unordered_map
	{
		struct KeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};

		typedef typename HashTable<K, pair<const K, V>, KeyOfT, hash>::Iterator iterator;
		typedef typename HashTable<K, pair<const K, V>, KeyOfT, hash>::ConstIterator const_iterator;

	public:

		iterator begin()
		{
			return ht.Begin();
		}

		iterator end()
		{
			return ht.End();
		}

		const_iterator begin() const
		{
			return ht.Begin();
		}

		const_iterator end() const
		{
			return ht.End();
		}

		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return ht.Insert(kv);
		}

		iterator find(const K& key)
		{
			return ht.Find(key);
		}

		bool erase(const K& key)
		{
			return ht.Erase(key);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = ht.Insert({key,V()});
			return ret.second;
		}


	private:
		HashTable<K, pair<const K,V>, KeyOfT,hash> ht;
	};
}